package com.yanjiali.service.impl;

import com.yanjiali.enumerate.UserRoleEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yanjiali.mapper.SysRoleMapper;
import com.yanjiali.entity.SysRole;
import com.yanjiali.service.SysRoleService;
/**
 * @Package: com.yanjiali.service.impl
 * @Author: yanjiali
 * @Created: 2025/4/10 22:35
*/
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements SysRoleService{

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public boolean isSuperAdmin(Long userId) {
        // 当用户的角色 code 为： ROLE_ADMIN 时，该用户为超级的管理员
        // 用户的 id-> 用户的角色 -> 该角色的 Code 是否为 ROLE_ADMIN
        String roleCode = sysRoleMapper.getUserRoleCode(userId);
        if (!StringUtils.isEmpty(roleCode) && roleCode.equals(UserRoleEnum.ROLE_ADMIN)) {
            return true;
        }
        return false;
    }
}
